package com.messaging;

import java.net.InetAddress;

/**
 * @author Dmitry
 */
public class Message {

    private final byte[] value;
    private final InetAddress address;
    private final int port;

    public Message(byte[] value, InetAddress address, int port) {
        this.value = value;
        this.address = address;
        this.port = port;
    }

    public int getPort() {
        return port;
    }

    public byte[] getValue() {
        return value;
    }

    public InetAddress getAddress() {
        return address;
    }

    public byte[] getRealData() {
        if ((value[0] & 0xC0) == 0xC0) {
            return null;
        } else if ((value[0] & 0x80) != 0) {
            byte[] realBuffer = new byte[value.length - 4];
            System.arraycopy(value, 6, realBuffer, 0, value.length - 4);
            return realBuffer;
        }else{
            byte[]realBuffer = new byte[value.length - 3];
            System.arraycopy(value, 3, realBuffer, 0, value.length - 1);
            return realBuffer;
        }
    }

}
